Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add fetch for default branch #1031

Merged
merged 5 commits into from
Apr 16, 2021
Merged

fix: Add fetch for default branch #1031

merged 5 commits into from
Apr 16, 2021

Conversation

billyjacobson
Copy link
Contributor

Add fetch for default branch so autogen files can use the correct default branch during migration

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Apr 8, 2021
@billyjacobson billyjacobson requested a review from bcoe April 8, 2021 17:23
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty reasonable to me, with the caveat that I think it would be good to add a test.

I think you could use something like requests-mock so that you don't need to actually care about the traffic to GitHub.

@@ -353,3 +359,9 @@ def _load_repo_metadata(metadata_file: str = "./.repo-metadata.json") -> Dict:
with open(metadata_file) as f:
return json.load(f)
return {}

def _get_default_branch_name(package_name: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this might not be used yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -58,6 +59,11 @@ def _generic_library(self, directory: str, **kwargs) -> Path:

t = templates.TemplateGroup(self._template_root / directory, self.excludes)

repo = kwargs["metadata"]["repository"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me, but I think it would be worth adding a test here:

https://github.com/googleapis/synthtool/blob/master/tests/test_templates.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a test

@@ -58,6 +59,11 @@ def _generic_library(self, directory: str, **kwargs) -> Path:

t = templates.TemplateGroup(self._template_root / directory, self.excludes)

repo = kwargs["metadata"]["repository"]
github_req = requests.get(f"https://api.github.com/repos/{repo}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SurferJeffAtGoogle Will this be problematic for owl-bot (as it's not hermetic)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Jeff is out til Friday? Is there anyone else we can ask about this? Or do you have thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me this seems like it's probably okay, as it will be applied in the post-processor, and will stay consistent for the repo itself?

@billyjacobson billyjacobson requested a review from bcoe April 9, 2021 15:23
@billyjacobson billyjacobson marked this pull request as ready for review April 12, 2021 15:02
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 15, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 15, 2021
@bcoe bcoe merged commit 898b38a into master Apr 16, 2021
@bcoe bcoe deleted the add-default-branch branch April 16, 2021 00:13
@bcoe
Copy link
Contributor

bcoe commented Apr 16, 2021

@billyjacobson thank you for adding this 👍 sorry it took a while to land, the beginning of the week was a bit swamped.

@@ -41,6 +43,14 @@ def test_handles_empty_string():
assert decamelize("") == ""


def test_get_default_branch():
with requests_mock.Mocker() as m:
m.get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate that you added a test for this 🆗

@SurferJeffAtGoogle
Copy link
Contributor

Sorry I didn't chime in on this sooner.

This is causing @sofisl and I problems because we're trying to generate templated code for a new library, that doesn't have a corresponding github repo yet.

With this PR, _generic_library() fetches data from the network during template generation. That's not what I imagined it would ever do. That also means it will fail whenever the network is flaky. It's very fragile.

@bcoe and @billyjacobson Can we observe or encode the default branch without making network requests?

@billyjacobson
Copy link
Contributor Author

billyjacobson commented May 11, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants